/*
 * TabTopbar.java
 * classes : com.house365.cdecoration.ui.view.TabTopbar
 * @author ruint
 * V 1.0.0
 * Create at 2014-8-7 上午9:57:38
 */
package com.ruint.master.view;

import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ruint.master.R;

/**
 * com.house365.cdecoration.ui.view.TabTopbar
 * 
 * @author ruint create at 2014-8-7 上午9:57:38
 */
public class TabTopbar extends Topbar implements TopbarConstantPool {

  private Context context;
  private TextView rightTab;
  private TextView leftTab;
  private ImageView rightButton;

  public TabTopbar(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    initializeView();
  }

  public TabTopbar(Context context) {
    super(context);
    this.context = context;
    initializeView();
  }

  private void initializeView() {
    makeCorrespondenceMap();
    LayoutInflater.from(context).inflate(R.layout.top_tab_layout, this);
    rightTab = (TextView) findViewById(R.id.topbar_right_tab);
    leftTab = (TextView) findViewById(R.id.topbar_left_tab);
    rightButton = (ImageView) findViewById(R.id.topbar_tab_rightbtn);
    findViewById(R.id.topbar_tab_back).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        ((Activity) context).onBackPressed();
      }
    });
  }

  public TextView getRightTab() {
    return this.rightTab;
  }

  public TextView getLeftTab() {
    return this.leftTab;
  }

  public ImageView getRightButton() {
    return this.rightButton;
  }

  public TabTopbar setTab(String tab1, String tab2, String btn) {
    getRightTab().setText(tab2);
    getLeftTab().setText(tab1);
    if (!TextUtils.isEmpty(btn))
      setRightButton(btn);
    return this;
  }

  @Override
  public void fetchRightBtn(ImageView view, String text) {
    view.setImageResource(correspondecneMap.get(text));
  }

  @Override
  public Map<String, Integer> makeCorrespondenceMap() {
    correspondecneMap.put(TOPBAR_BUTTON_SUBMIT, TOPBAR_BUTTON_SUBMIT_ID);
    correspondecneMap.put(TOPBAR_BUTTON_CREATE_DIARY, TOPBAR_BUTTON_CREATE_DIARY_ID);
    correspondecneMap.put(TOPBAR_BUTTON_COLLECT, TOPBAR_BUTTON_COLLECT_ID);
    correspondecneMap.put(TOPBAR_BUTTON_SCREEN, TOPBAR_BUTTON_SCREEN_ID);
    correspondecneMap.put(TOPBAR_BUTTON_SEARCH, TOPBAR_BUTTON_SEARCH_ID);
    correspondecneMap.put(TOPBAR_BUTTON_HELP, TOPBAR_BUTTON_HELP_ID);
    correspondecneMap.put(TOPBAR_BUTTON_ILLUSTATE, TOPBAR_BUTTON_ILLUSTATE_ID);
    correspondecneMap.put(TOPBAR_BUTTON_MORE, TOPBAR_BUTTON_MORE_ID);
    correspondecneMap.put(TOPBAR_BUTTON_SAVE, TOPBAR_BUTTON_SAVE_ID);
    correspondecneMap.put(TOPBAR_BUTTON_CONCERN, TOPBAR_BUTTON_CONCERN_ID);
    correspondecneMap.put(TOPBAR_BUTTON_UNCONCERN, TOPBAR_BUTTON_UNCONCERN_ID);
    correspondecneMap.put(TOPBAR_BUTTON_COLLECTED, TOPBAR_BUTTON_COLLECTED_ID);
    return correspondecneMap;
  }

  @Override
  public TabTopbar setRightButton(String text) {
    rightButton.setVisibility(View.VISIBLE);
    fetchRightBtn(getRightButton(), text);
    return this;
  }

  @Override
  public TabTopbar setRightButton(int resId) {
    return null;
  }
}
